class Scene6 extends BaseScreen{
	public constructor() {
		super();
		this.skinName = "resource/eui_skins/Scene6Skin.exml";
	}
    private question = [
        {
            'content':'城管进社区“一人一居”工作方式指：_____',
            'a':'三名一线城管队员对应两个居委会，定期走访，听取群众意见。 ',
            'b':'三名一线城管队员对应一个居委会，定期走访，听取群众意见。 ',
            'c':'一名一线城管队员对应两个居委会，定期走访，听取群众意见。 ',
            'd':'两名一线城管队员对应一个居委会，定期走访，听取群众意见。 ',
            'answer':'A',
            'user':''
        },
        {
            'content':'静安区现有266个居委会，目前责任区划分、《城管社区工作室工作联系册》已经做到100%全覆盖，并于今年9月底前完成了几个城管进社区示范点建设？',
            'a':'21个',
            'b':'31个',
            'c':'41个',
            'd':'51个',
            'answer':'B',
            'user':''
        },
        {
            'content':'数据显示，今年1月至9月间，静安区城市管理行政执法局共收到各类投诉4813件，同比下降_____%？',
            'a':'36%',
            'b':'36%',
            'c':'36%',
            'd':'36%',
            'answer':'C',
            'user':''
        }
    ]
    private curIndex:number;
    private prevbtn:eui.Image;
    private next1btn:eui.Image;
    private next2btn:eui.Image;
    private submitbtn:eui.Image;
    private currentlab:eui.Label;
    private questionitem:eui.Label;
    private itemA:eui.Group;
    private itemB:eui.Group;
    private itemC:eui.Group;
    private itemD:eui.Group;
    private A:eui.Image;
    private B:eui.Image;
    private C:eui.Image;
    private D:eui.Image;
    private Acnt:eui.Label;
    private Bcnt:eui.Label;
    private Ccnt:eui.Label;
    private Dcnt:eui.Label;
    private canAnswer:boolean;
	protected childrenCreated(): void {
        super.childrenCreated();
        this.initView();
    }

	private initView():void
	{
        this.Acnt.maxWidth = this.questionitem.width * 0.9;
        this.Bcnt.maxWidth = this.questionitem.width * 0.9;
        this.Ccnt.maxWidth = this.questionitem.width * 0.9;
        this.Dcnt.maxWidth = this.questionitem.width * 0.9;
        this.A.name = 'A';
        this.B.name = 'B';
        this.C.name = 'C';
        this.D.name = 'D';

        this.curIndex = 1;
        this.addEvent();
        this.canAnswer = false;
        this.updateQuestion(this.curIndex);
        this.buttonShow(this.curIndex);
	}

    private addEvent():void{
        this.prevbtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.prevQuestionHandle,this);
        this.next1btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.nextQuestionHandle,this);
        this.next2btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.nextQuestionHandle,this);
        this.submitbtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.submitQuestionHandle,this);

        this.A.addEventListener(egret.TouchEvent.TOUCH_TAP,this.answerQuestion,this);
        this.B.addEventListener(egret.TouchEvent.TOUCH_TAP,this.answerQuestion,this);
        this.C.addEventListener(egret.TouchEvent.TOUCH_TAP,this.answerQuestion,this);
        this.D.addEventListener(egret.TouchEvent.TOUCH_TAP,this.answerQuestion,this);
    }

    private answerQuestion(evt:egret.TouchEvent):void{
        if(this.canAnswer == false){
            return ;
        }
        this.canAnswer = false;
        console.log(evt.target.name);
        var img:eui.Image = evt.target as eui.Image;
        var answer:string = img.name;
        this.question[this.curIndex-1].user = answer;
        this.checkAnswer(answer);
    }

    private checkAnswer(useranswer):void{
        var rightAnswer:string = this.question[this.curIndex-1].answer;
        if(rightAnswer == useranswer){
            this[useranswer].source = 'btn6_11';
        }
        else{
            this[useranswer].source = 'btn6_2';
            this[rightAnswer].source = 'btn6_11';
        }
    }

    private nextQuestionHandle(evt:egret.TouchEvent):void{
        if(this.question[this.curIndex-1].user == ''){
            return;
        }
        this.curIndex++;
        this.updateQuestion(this.curIndex);
        this.buttonShow(this.curIndex);
    }

    private submitQuestionHandle(evt:egret.TouchEvent):void{
        utils.AlertManager.instance.showAlert('AnswerOK',false);
    }

    private prevQuestionHandle(evt:egret.TouchEvent):void{
        this.curIndex--;
        this.updateQuestion(this.curIndex);
        this.buttonShow(this.curIndex);
    }

    private updateQuestion(flag):void{
        this.questionitem.text = this.question[flag-1].content;
        this.Acnt.text = this.question[flag-1].a;
        this.Bcnt.text = this.question[flag-1].b;
        this.Ccnt.text = this.question[flag-1].c;
        this.Dcnt.text = this.question[flag-1].d;
        this.questionitem.lineSpacing = 3;
        this.Acnt.lineSpacing = 3;
        this.Bcnt.lineSpacing = 3;
        this.Ccnt.lineSpacing = 3;
        this.Dcnt.lineSpacing = 3;
        this.itemA.y = this.questionitem.height + this.questionitem.y + 40;
        this.itemB.y = this.itemA.y + this.itemA.height + 20;
        this.itemC.y = this.itemB.y + this.itemB.height + 20;
        this.itemD.y = this.itemC.y + this.itemC.height + 20;
        this.A.source = 'btn6_3';
        this.B.source = 'btn6_3';
        this.C.source = 'btn6_3';
        this.D.source = 'btn6_3';
        
        if(this.question[this.curIndex-1].user == ''){
            this.canAnswer = true;
        }
        else{
            this.checkAnswer(this.question[this.curIndex-1].user);
            this.canAnswer = false;
        }
    }

    private buttonShow(flag):void{
        switch(flag){
            case 1:
                this.prevbtn.visible = false;
                this.next1btn.visible = true;
                this.next2btn.visible = false;
                this.submitbtn.visible = false;
                break;
            case 2:
                this.prevbtn.visible = true;
                this.next1btn.visible = false;
                this.next2btn.visible = true;
                this.submitbtn.visible = false;
                break;
            case 3:
                this.prevbtn.visible = true;
                this.next1btn.visible = false;
                this.next2btn.visible = false;
                this.submitbtn.visible = true;
                break;
        }
        this.currentlab.text = flag;
    }

	public resize(): void {
        super.resize();
    }

    public dispose(): void {
        TweenMax.killAll(false, false, true);
        TweenMax.killChildTweensOf(this);
    }
}